<template>
	<!-- 添加或修改月度补贴记录对话框 -->
	<el-dialog :title="dialogTitle" :visible.sync="visible" width="560px" append-to-body>
		<el-form ref="form" :model="formData" :rules="formRules" label-width="86px">
			<el-row :gutter="16">
				<el-col :span="24">
					<el-form-item label="保密人员" prop="userId">
						<person-select v-model="formData.userId" :list="checkedUsers" :disabled="isDisabled"></person-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="涉密等级" prop="spLevel">
						<el-select v-model="formData.spLevel" placeholder="选择涉密等级" style="width: 100%" disabled>
							<el-option v-for="(item, index) in dict.type.sp_level" :key="index" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="补贴年月" prop="yearMonth">
						<el-date-picker v-model="formData.yearMonth" v-bind="dateConfig" @change="handleDateChange"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="补贴金额" prop="money">
						<el-input-number v-model="formData.money" controls-position="right" placeholder="请输入补贴金额" style="width: 100%"></el-input-number>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template slot="footer">
			<el-button type="primary" @click="handleSubmitData()">确定</el-button>
			<el-button @click="visible = false">取消</el-button>
		</template>
	</el-dialog>
</template>

<script>
import formMixins from '../common/formMixins';
import { getMoney, addMoney, updateMoney } from '@/api/personnal/subsidy';
export default {
	mixins: [formMixins],
	dicts: ['sp_level'],
	data() {
		return {
			formName: '月度补贴',
			formRules: {
				userId: { required: true, message: '请选择保密人员', trigger: 'change' },
				yearMonth: { required: true, message: '请选择补贴年月', trigger: 'change' },
				spLevel: { required: true, message: '请选择涉密等级', trigger: 'change' },
				money: { required: true, message: '请输入追责说明', trigger: 'blur' }
			},
			dateConfig: {
				type: 'month',
				editable: false,
				format: 'yyyy年MM月',
				valueFormat: 'yyyy-MM',
				style: { width: '100%' },
				placeholder: '选择补贴年月'
			}
		};
	},
	computed: {
		detailFunction() {
			return eval(getMoney);
		},
		callFunction() {
			return eval(this.addOrEdit ? addMoney : updateMoney);
		}
	},
	watch: {
		userDetail(data) {
			let datas = this.formData;
			let yearMonth = `${datas.year}-${datas.month}`;
			this.$set(this.formData, 'userName', data.name);
			this.$set(this.formData, 'yearMonth', yearMonth);
			this.$set(this.formData, 'spLevel', data.spLevel);
		}
	},
	methods: {
		handleDateChange(date) {
			let dateArr = !date ? [] : date.split('-');
			this.$set(this.formData, 'year', dateArr[0]);
			this.$set(this.formData, 'month', dateArr[1]);
		},

		//格式化请求参数
		formatRequestParams() {
			let params = { ...this.formData };
			return params;
		}
	}
};
</script>
<style>
.el-month-table td.current:not(.disabled) .cell {
	line-height: 34px;
	box-sizing: border-box;
	border: solid 1px #1890ff;
}
</style>
